﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace SharpObjects.Multithreading_Test
{
    public class Job : IJob
    {
        static object syncRoot = new object();

        public string Message { get; set; }
        public TimeSpan Delay { get; set; }

        public void Execute(ThreadContext threadContext)
        {
            lock (syncRoot)
            {
                Console.WriteLine("\n---------------\n{0}, {1}", Thread.CurrentThread.Name, threadContext.Label);
                Console.WriteLine("Job count for this thread: {0}, Message: {1}", threadContext.GetAndIncrementCount(), this.Message);
                Console.WriteLine("Thread {0} is going to sleep for {1}", Thread.CurrentThread.Name, this.Delay);
            }

            Thread.Sleep(this.Delay);
        }
    }
}
